<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\ForumBbsCategory;
use app\common\model\ForumBbsLevel;
use app\common\model\GamblerKing;
use app\common\model\GamblerKingAction;
use app\common\model\KingCategory;

/**
 * 赌王控制器
 */
class King extends AdminBase
{

    /**
     * 赌王列表
     */
    public function kingList()
    {

        // $where = $this->logicKing->getWhere($this->param);
        $this->param['state'] = 2;
        $this->assign('list', $this->logicKing->getkingList($this->param, 'a.*', 'a.create_time desc'));
        $this->assign('tags', KingCategory::all(['status' => 1, 'parent_id' => ['neq', 0]]));
        $this->assign('param', $this->param);
        return $this->fetch('king_list');
    }

    /**
     * 申请赌王列表
     */
    public function apply_king_list()
    {

        // $where = $this->logicKing->getWhere($this->param);
        $this->param['is_apply'] = 1;
        $this->assign('list', $this->logicKing->getkingList($this->param, 'a.*', 'a.create_time desc'));
        $this->assign('tags', KingCategory::all(['status' => 1, 'parent_id' => ['neq', 0]]));
        $this->assign('param', $this->param);
        return $this->fetch('apply_king_list');
    }

    /**
     * 赌王委托统计列表
     */
    public function king_statistics()
    {

        // $where = $this->logicKing->getWhere($this->param);
        $this->param['state'] = 2;
        $this->assign('list', $this->logicKing->getkingList($this->param, 'a.*,m.nickname', 'a.create_time desc'));
        $this->assign('tags', KingCategory::all(['status' => 1, 'parent_id' => ['neq', 0]]));
        $this->assign('param', $this->param);
        return $this->fetch('king_statistics');
    }


    /**
     * 赌王添加
     */
    public function kingAdd()
    {

        $this->kingCommon();

        return $this->fetch('king_edit');
    }

    /**
     * 赌王编辑
     */
    public function kingEdit()
    {

        $this->kingCommon();

        $info = $this->logicKing->getkingInfo(['a.id' => $this->param['id']], 'a.*');


        $this->assign('info', $info);
        $this->assign('tags', KingCategory::all(['status' => 1, 'parent_id' => ['neq', 0]]));
        return $this->fetch('king_edit');
    }

    /**
     * 赌王添加与编辑通用方法
     */
    public function kingCommon()
    {

//      IS_POST && $this->jump($this->logicKing->kingEdit($this->param));
        IS_POST && $this->jump($this->logicKing->kingEdit($_POST));

        $this->assign('tags', KingCategory::all(['status' => 1]));

    }


    /**
     * 数据状态设置
     */
    public function setStatus()
    {
        if (!empty($this->param['level'])) {
            $this->jump($this->logicAdminBase->setStatus('KingCategory', $this->param));
        }
        $this->jump($this->logicAdminBase->setStatus('GamblerKing', $this->param));
    }

    /**
     * 数据状态设置
     */
    public function update_info()
    {

        $this->jump($this->logicKing->update_info($this->param));
    }


    /**
     * 赌王分类添加
     */
    public function kingLevelAdd()
    {

        IS_POST && $this->jump($this->logicKing->kingLevelEdit($this->param));

        return $this->fetch('king_level_edit');
    }

    /**
     * 赌王分类编辑
     */
    public function kingLevelEdit()
    {

        IS_POST && $this->jump($this->logicKing->kingLevelEdit($this->param));

        $info = $this->logicKing->getkingLevelInfo(['id' => $this->param['id']]);

        $this->assign('info', $info);

        return $this->fetch('king_level_edit');
    }

    /**
     * 赌王分类列表
     */
    public function kingLevelList()
    {

        $this->assign('list', $this->logicKing->getKingLevelList(['parent_id' => 0]));

        return $this->fetch('king_level_list');
    }

    /**
     * 赌王强项列表
     */
    public function kingLevelListStrengths()
    {

        if (!empty($this->param['parent_id'])) {
            $where['parent_id'] = $this->param['parent_id'];
        } else {
            $where = ['parent_id' => ['gt', 0]];
        }
        !empty($this->param['search_data']) && $where['name'] = ['like', '%' . $this->param['search_data'] . '%'];

        $this->assign('list', $this->logicKing->getKingLevelList($where));
        $this->assign('param', $this->param);
        $this->assign('parent_list', $this->logicKing->getKingLevelList(['parent_id' => 0], '', '', false));
        return $this->fetch('king_level_list_strengths');
    }

    /**
     * 赌王分类添加
     */
    public function kingLevelStrengthsAdd()
    {

        IS_POST && $this->jump($this->logicKing->kingLevelEdit($this->param));
        $this->assign('parent_list', $this->logicKing->getKingLevelList(['parent_id' => 0], '', '', false));
        return $this->fetch('king_level_strengths_edit');
    }

    /**
     * 赌王分类添加
     */
    public function kingLevelStrengthsEdit()
    {
        IS_POST && $this->jump($this->logicKing->kingLevelEdit($this->param));
        $info = $this->logicKing->getkingLevelInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);
        $this->assign('parent_list', $this->logicKing->getKingLevelList(['parent_id' => 0], '', '', false));
        return $this->fetch('king_level_strengths_edit');
    }


    /**
     * 赌王分类删除
     */
    public function kingLevelDel()
    {

        $this->jump($this->logicAdminBase->setStatus('KingCategory', $this->param));
    }


    /**
     * 赌王动态添加
     */
    public function kingActionAdd()
    {

        IS_POST && $this->jump($this->logicKing->kingActionEdit($_POST));
        $this->assign('king', GamblerKing::all(['status' => 1]));
        return $this->fetch('king_action_edit');
    }

    /**
     * 赌王动态编辑
     */
    public function kingActionEdit()
    {

        IS_POST && $this->jump($this->logicKing->kingActionEdit($_POST));

        $info = GamblerKingAction::get($this->param['id']);
        $this->assign('king', GamblerKing::all(['status' => 1]));
        $this->assign('info', $info);

        return $this->fetch('king_action_edit');
    }

    /**
     * 赌王动态列表
     */
    public function kingActionList()
    {

        $this->assign('list', $this->logicKing->getKingActionList());
        $this->assign('king', GamblerKing::all(['status' => 1]));
        $this->assign('param', $this->param);
        return $this->fetch('king_action_list');
    }

    /**
     *赌王动态删除
     */
    public function kingActionDel($id = 0)
    {

        $this->jump($this->logicKing->kingActionDel(['id' => $id]));
    }

    /**
     * 赌王信用分等级列表
     */
    public function kingCreditLevelList()
    {

        $this->assign('list', $this->logicKing->KingCreditLevelList());

        return $this->fetch('king_credit_level_list');
    }


    /**
     * 赌王信用分等级添加
     */
    public function kingCreditLevelAdd()
    {

        IS_POST && $this->jump($this->logicKing->kingCreditLevelEdit($this->param));
        return $this->fetch('king_credit_level_edit');
    }

    /**
     * 赌王信用分等级编辑
     */
    public function kingCreditLevelEdit()
    {
        IS_POST && $this->jump($this->logicKing->kingCreditLevelEdit($this->param));
        $info = $this->logicKing->getkingCreditLevelInfo(['id' => $this->param['id']]);
        $this->assign('info', $info);

        return $this->fetch('king_credit_level_edit');
    }


    /**
     * 赌王信用分等级删除
     */
    public function kingCreditLevelDel()
    {

        $this->jump($this->logicAdminBase->setStatus('KingCreditLevel', $this->param));
    }


    /**
     * 赌王心语列表
     */
    public function kingDescribeList()
    {
        $where['type'] = 1;
        $this->assign('list', $this->logicKing->getKingDescribeList($where));
        $this->assign('type', 1);
        return $this->fetch('king_describe_list');
    }

    /**
     * 赌王履历列表
     */
    public function kingDescribeList1()
    {
        $where['type'] = 2;
        $this->assign('list', $this->logicKing->getKingDescribeList($where));
        $this->assign('type', 2);
        return $this->fetch('king_describe_list');
    }


    /**
     * 赌王心语添加
     */
    public function kingDescribeAdd()
    {

        IS_POST && $this->jump($this->logicKing->kingDescribeEdit($_POST));
        $this->assign('type', $this->param['type']);
        return $this->fetch('king_describe_edit');
    }

    /**
     * 赌王心语编辑
     */
    public function kingDescribeEdit()
    {
        IS_POST && $this->jump($this->logicKing->kingDescribeEdit($_POST));
        $info = $this->logicKing->getKingDescribeInfo(['id' => $this->param['id']]);
        $this->assign('type', $info['type']);
        $this->assign('info', $info);

        return $this->fetch('king_describe_edit');
    }


    /**
     * 赌王心语删除
     */
    public function kingDescribeDel()
    {

        $this->jump($this->logicAdminBase->setStatus('KingDescribe', $this->param));
    }

    /**
     * 排序
     */
    public function setSort()
    {

        $this->jump($this->logicAdminBase->setSort('GamblerKing', $this->param));
    }

    /***
     * 赌王订单管理
     */

    public function king_order_list()
    {
        if (!empty($this->param['user_investment_id'])) {
            $this->assign('list', $this->logicKing->getShowUserList($this->param, 'a.*,c.username,c.mobile,c.is_company,c.level_id,c.create_time as reg_time', 'a.create_time desc'));
            $this->assign('param', $this->param);
            return $this->fetch('show_user');
        } else {
            $this->assign('list', $this->logicKing->getKingOrderList($this->param, 'a.*', 'a.create_time desc'));
            $this->assign('param', $this->param);
            return $this->fetch();
        }

    }


    /**
     * 赌王订单状态修改
     */
    public function king_order_update()
    {

            $this->jump($this->logicKing->king_order_update($this->param));



    }

    /**
     * 赌王产品修改
     */
    public function king_investment_update()
    {
        IS_POST && $this->jump($this->logicKing->kingbonus($this->param));
        if (isset($this->param['otcorder'])) {
            $this->assign('param', $this->param);
            return $this->fetch();
        } else {
            $this->jump($this->logicKing->king_investment_update($this->param));
        }
    }


}
